<!DOCTYPE html>
<!--
  Copyright 2016 Google Inc.

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
-->
<html>
  <head>
    <meta charset="utf-8">
    <title>Text Field - Material Components Catalog</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/png" href="/images/logo_components_color_2x_web_48dp.png">
    <link rel="stylesheet" href="/assets/text-field.css">
    <script src="/ready.js"></script>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <style>
      input[type="checkbox"]:disabled + label {
        opacity: .4;
      }

      .example {
        margin: 24px;
        padding: 24px;
      }

      .hero .mdc-text-field {
        min-width: 240px;
      }

      .demo-note {
        padding: 20px;
        margin: 20px 0;
        background-color: #f2f2f2;
      }

      .full-width-textarea-example {
        margin-top: 16px;
      }
    </style>
  </head>
  <body class="mdc-typography">
    <header class="mdc-toolbar mdc-toolbar--fixed">
      <div class="mdc-toolbar__row">
        <section class="mdc-toolbar__section mdc-toolbar__section--align-start">
          <a href="/" class="catalog-back mdc-toolbar__menu-icon"><i class="material-icons">&#xE5C4;</i></a>
          <span class="mdc-toolbar__title catalog-title">Text Field</span>
        </section>
      </div>
    </header>
    <main>
      <div class="mdc-toolbar-fixed-adjust"></div>
      <section class="hero">
        <div class="mdc-text-field">
          <input type="text" class="mdc-text-field__input" id="my-text-field">
          <label for="my-text-field" class="mdc-floating-label">Text Field</label>
          <div class="mdc-line-ripple"></div>
        </div>
      </section>

      <section class="example">
        <h2>Full Functionality JS Component (Floating Label, Validation)</h2>
        <section id="demo-text-field-wrapper" class="demo-text-field-wrapper">
          <div class="mdc-text-field">
            <input type="text" class="mdc-text-field__input" id="full-func-text-field"
                   aria-controls="my-text-field-helper-text"
                   aria-describedby="my-text-field-helper-text">
            <label for="full-func-text-field" class="mdc-floating-label">Email Address</label>
            <div class="mdc-line-ripple"></div>
          </div>
          <p id="my-text-field-helper-text" class="mdc-text-field-helper-text"
             aria-hidden="true" style="visibility: hidden">Helper Text</p>
        </section>
        <div>
          <input id="disable" type="checkbox">
          <label for="disable">Disabled</label>
        </div>
        <div>
          <input id="rtl" type="checkbox">
          <label for="rtl">RTL</label>
        </div>
        <div>
          <input id="dense" type="checkbox">
          <label for="dense">Dense</label>
        </div>
        <div>
          <input id="required" type="checkbox">
          <label for="required">Required</label>
        </div>
        <div>
          <input id="alternate-colors" type="checkbox">
          <label for="alternate-colors">Alternate Colors</label>
        </div>
        <div>
          <input id="use-helper-text" type="checkbox">
          <label for="use-helper-text">Use Helper Text</label>
        </div>
        <div>
          <input id="persistent-helper-text" type="checkbox" disabled>
          <label for="persistent-helper-text">Make helper text persistent</label>
        </div>
        <div>
          <input id="helper-text-as-validation" type="checkbox" disabled>
          <label for="helper-text-as-validation">
            Use helper text as validation message
          </label>
        </div>
      </section>

      <section class="example">
        <h2>Password field with validation</h2>
        <div class="mdc-text-field">
          <input required pattern=".{8,}" type="password" class="mdc-text-field__input" id="pw"
                 aria-controls="pw-validation-msg"
                 aria-describedby="pw-validation-msg"
                 autocomplete="current-password">
          <label for="pw" class="mdc-floating-label">Choose password</label>
          <div class="mdc-line-ripple"></div>
        </div>
        <p class="mdc-text-field-helper-text mdc-text-field-helper-text--persistent mdc-text-field-helper-text--validation-msg"
           id="pw-validation-msg">Must be at least 8 characters long</p>
      </section>

      <section class="example">
        <h2>Outlined Text Field</h2>
        <div id="demo-tf-outlined-wrapper" class="demo-text-field-wrapper">
          <div id="tf-outlined-example" class="mdc-text-field mdc-text-field--outlined" data-demo-no-auto-js>
            <input type="text" id="tf-outlined-input" class="mdc-text-field__input"
                   aria-controls="name-validation-message"
                   aria-describedby="name-validation-message">
            <label for="tf-outlined-input" class="mdc-floating-label">Your Name</label>
            <div class="mdc-notched-outline">
              <svg>
                <path class="mdc-notched-outline__path"/>
              </svg>
            </div>
            <div class="mdc-notched-outline__idle"></div>
          </div>
          <p class="mdc-text-field-helper-text mdc-text-field-helper-text--validation-msg"
             id="name-validation-message">Helper Text</p>
        </div>
        <div>
          <input id="outlined-disable" type="checkbox">
          <label for="outlined-disable">Disabled</label>
        </div>
        <div>
          <input id="outlined-rtl" type="checkbox">
          <label for="outlined-rtl">RTL</label>
        </div>
        <div>
          <input id="outlined-custom-colors" type="checkbox">
          <label for="outlined-custom-colors">Alternate Colors</label>
        </div>
        <div>
          <input id="outlined-dense" type="checkbox">
          <label for="outlined-dense">Dense</label>
        </div>
        <div>
          <input id="outlined-required" type="checkbox">
          <label for="outlined-required">Required</label>
        </div>
        <div>
          <input id="outlined-minlength" type="checkbox">
          <label for="outlined-minlength">Must be at least 8 characters</label>
        </div>
        <div>
          <input id="outlined-maxlength" type="checkbox">
          <label for="outlined-maxlength">Must not exceed 10 characters</label>
        </div>
      </section>

      <section class="example" id="demo-tf-icon-container">
        <h2>Text Field - Leading/Trailing icons</h2>
        <div id="demo-tf-leading-wrapper" class="demo-tf-add-space">
          <div id="tf-leading-example"
            class="mdc-text-field mdc-text-field--with-leading-icon" data-demo-no-auto-js>
            <i class="material-icons mdc-text-field__icon" tabindex="0" role="button">event</i>
            <input type="text" id="tf-leading" class="mdc-text-field__input">
            <label for="tf-leading" class="mdc-floating-label">Your name</label>
            <div class="mdc-line-ripple"></div>
          </div>
        </div>
        <div id="demo-tf-trailing-wrapper" class="demo-tf-add-space">
          <div id="tf-trailing-example"
            class="mdc-text-field mdc-text-field--with-trailing-icon" data-demo-no-auto-js>
            <input type="text" id="tf-trailing" class="mdc-text-field__input">
            <label for="tf-trailing" class="mdc-floating-label">Your other name</label>
            <i class="material-icons mdc-text-field__icon" tabindex="0" role="button">delete</i>
            <div class="mdc-line-ripple"></div>
          </div>
        </div>
        <div id="demo-tf-outlined-leading-wrapper" class="demo-tf-add-space">
          <div id="tf-outlined-leading-example"
            class="mdc-text-field mdc-text-field--outlined mdc-text-field--with-leading-icon" data-demo-no-auto-js>
            <i class="material-icons mdc-text-field__icon" tabindex="0" role="button">event</i>
            <input type="text" id="tf-outlined-leading" class="mdc-text-field__input">
            <label for="tf-outlined-leading" class="mdc-floating-label">Your other name</label>
            <div class="mdc-notched-outline">
              <svg>
                <path class="mdc-notched-outline__path"/>
              </svg>
            </div>
            <div class="mdc-notched-outline__idle"></div>
          </div>
        </div>
        <div id="demo-tf-outlined-trailing-wrapper" class="demo-text-field-wrapper demo-tf-add-space">
          <div id="tf-outlined-trailing-example"
            class="mdc-text-field mdc-text-field--outlined mdc-text-field--with-trailing-icon" data-demo-no-auto-js>
            <input type="text" id="tf-outlined-trailing" class="mdc-text-field__input">
            <label for="tf-outlined-trailing" class="mdc-floating-label">Your other name</label>
            <i class="material-icons mdc-text-field__icon" tabindex="0" role="button">delete</i>
            <div class="mdc-notched-outline">
              <svg>
                <path class="mdc-notched-outline__path"/>
              </svg>
            </div>
            <div class="mdc-notched-outline__idle"></div>
          </div>
        </div>
        <div>
          <input id="disable-leading-trailing" type="checkbox">
          <label for="disable-leading-trailing">Disabled</label>
        </div>
        <div>
          <input id="rtl-leading-trailing" type="checkbox">
          <label for="rtl-leading-trailing">RTL</label>
        </div>
        <div>
          <input id="dense-leading-trailing" type="checkbox">
          <label for="dense-leading-trailing">Dense</label>
        </div>
        <div>
          <input id="unclickable-leading-trailing" type="checkbox">
          <label for="unclickable-leading-trailing">Unclickable icons</label>
        </div>
        <div>
          <input id="leading-trailing-alternate-colors" type="checkbox">
          <label for="leading-trailing-alternate-colors">Alternate Colors</label>
        </div>
        <div>
          <input id="required-leading-trailing" type="checkbox">
          <label for="required-leading-trailing">Required</label>
        </div>
        <div>
          <input id="pattern-leading-trailing" type="checkbox">
          <label for="pattern-leading-trailing">Must be at least 8 characters</label>
        </div>
      </section>

      <section class="example">
        <h2>Preventing FOUC</h2>
        <div class="mdc-text-field">
          <input id="fouc" type="text" class="mdc-text-field__input" value="Pre-filled value">
          <label for="fouc" class="mdc-floating-label mdc-floating-label--float-above">
            Label floating above
          </label>
          <div class="mdc-line-ripple"></div>
        </div>
      </section>

      <section class="example">
        <h2>Textarea</h2>
        <section id="demo-text-field-textarea-wrapper" class="demo-text-field-wrapper">
          <div class="mdc-text-field mdc-text-field--textarea">
            <textarea id="textarea" class="mdc-text-field__input" rows="8" cols="40"></textarea>
            <label for="textarea" class="mdc-floating-label">Textarea Label</label>
          </div>
        </section>
        <div>
          <input id="textarea-disable" type="checkbox">
          <label for="textarea-disable">Disabled</label>
        </div>
        <div>
          <input id="textarea-rtl" type="checkbox">
          <label for="textarea-rtl">RTL</label>
        </div>
        <div>
          <input id="textarea-alternate-colors" type="checkbox">
          <label for="textarea-alternate-colors">Alternate Colors</label>
        </div>
        <div>
          <input id="textarea-required" type="checkbox">
          <label for="textarea-required">Required</label>
        </div>
      </section>

      <section class="example">
        <h2>Full-Width Text Field and Textarea</h2>
        <div id="demo-fullwidth-wrapper" class="demo-text-field-wrapper">
          <div class="mdc-text-field mdc-text-field--fullwidth">
            <input class="mdc-text-field__input" type="text" placeholder="Subject" aria-label="Subject">
            <div class="mdc-line-ripple"></div>
          </div>
          <div class="mdc-text-field mdc-text-field--textarea mdc-text-field--fullwidth full-width-textarea-example">
            <textarea id="full-width-textarea" class="mdc-text-field__input" rows="8"></textarea>
            <label for="full-width-textarea" class="mdc-floating-label">Textarea Label</label>
          </div>
        </div>
        <div>
          <input type="checkbox" id="fullwidth-disable">
          <label for="fullwidth-disable">Disabled</label>
        </div>
        <div>
          <input type="checkbox" id="fullwidth-dense">
          <label for="fullwidth-dense">Dense</label>
        </div>
        <div>
          <input id="fullwidth-required" type="checkbox">
          <label for="fullwidth-required">Required</label>
        </div>
        <div>
          <input id="fullwidth-alternate-colors" type="checkbox">
          <label for="fullwidth-alternate-colors">Alternate Colors</label>
        </div>
      </section>

      <section class="example">
        <h2>Custom error state behaviour - remove error state as soon as invalid input is resolved</h2>
        <section id="demo-text-field-wrapper">
          <div class="mdc-text-field" id="demo-textfield-error-state">
            <input type="text" pattern="^\d{10}$" id="demo-textfield-error-state-input" class="mdc-text-field__input">
            <label class="mdc-floating-label" for="demo-textfield-error-state-input">Phone number</label>
            <div class="mdc-line-ripple"></div>
          </div>
          <p id="username-helper-text" class="mdc-text-field-helper-text mdc-text-field-helper-text--persistent mdc-text-field-helper-text--validation-msg" aria-hidden="true"
            >Enter 10 digit phone number including area code</p>
        </section>
      </section>
    </main>

    <script src="/assets/material-components-web.js" async></script>
    <script>
      function toggleRequired(textfield, isRequired) {
        textfield.required = isRequired;
      }

      function togglePattern(textfield, checked) {
        textfield.pattern = checked ? '.{8,}' : '.*';
      }

      demoReady(function() {
        var tfEl = document.getElementById('tf-outlined-example');
        var tfHelperText = document.getElementById('tf-outlined-validation-msg');
        var tf = new mdc.textField.MDCTextField(tfEl);
        var outlinedInputEl = tfEl.querySelector('input');
        var wrapper = document.getElementById('demo-tf-outlined-wrapper');
        var plainHelperText = 'Helper Text';
        var minLengthError = 'Must be at least 8 characters';
        var maxLengthError = 'Must not exceed 10 characters';

        document.getElementById('outlined-disable').addEventListener('change', function(evt) {
          tf.disabled = evt.target.checked;
        });
        document.getElementById('outlined-rtl').addEventListener('change', function(evt) {
          if (evt.target.checked) {
            wrapper.setAttribute('dir', 'rtl');
          } else {
            wrapper.removeAttribute('dir');
          }
          tf.layout();
        });
        document.getElementById('outlined-custom-colors').addEventListener('change', function(evt) {
          tfEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-colors');
          tfEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-error-colors');
        });
        document.getElementById('outlined-dense').addEventListener('change', function(evt) {
          tfEl.classList[evt.target.checked ? 'add' : 'remove']('mdc-text-field--dense');
          tf.layout();
        });
        document.getElementById('outlined-required').addEventListener('change', function(evt) {
          toggleRequired(tf, evt.target.checked);
        });
        document.getElementById('outlined-minlength').addEventListener('change', function(evt) {
          tf.minLength = evt.target.checked ? 8 : 0;
        });
        document.getElementById('outlined-maxlength').addEventListener('change', function(evt) {
          tf.maxLength = evt.target.checked ? 10 : -1;
        });
        outlinedInputEl.addEventListener('blur', function() {
          if (outlinedInputEl.validity.tooShort) {
            tf.helperTextContent = minLengthError;
          } else if (outlinedInputEl.validity.tooLong) {
            tf.helperTextContent = maxLengthError;
          } else {
            tf.helperTextContent = plainHelperText;
          }
        });
      });

      demoReady(function() {
        var tfs = document.querySelectorAll(
          '.mdc-text-field:not([data-demo-no-auto-js])'
        );
        for (var i = 0, tf; tf = tfs[i]; i++) {
          mdc.textField.MDCTextField.attachTo(tf);
        }
      });

      demoReady(function() {
        var tfIconContainer = document.getElementById('demo-tf-icon-container');

        var tfLeadingEl = document.getElementById('tf-leading-example');
        var tfLeading = new mdc.textField.MDCTextField(tfLeadingEl);
        var wrapperLeading = document.getElementById('demo-tf-leading-wrapper');

        var tfTrailingEl = document.getElementById('tf-trailing-example');
        var tfTrailing = new mdc.textField.MDCTextField(tfTrailingEl);
        var wrapperTrailing = document.getElementById('demo-tf-trailing-wrapper');

        var tfOutlinedLeadingEl = document.getElementById('tf-outlined-leading-example');
        var tfOutlinedLeading = new mdc.textField.MDCTextField(tfOutlinedLeadingEl);
        var wrapperOutlinedLeading = document.getElementById('demo-tf-outlined-leading-wrapper');

        var tfOutlinedTrailingEl = document.getElementById('tf-outlined-trailing-example');
        var tfOutlinedTrailing = new mdc.textField.MDCTextField(tfOutlinedTrailingEl);
        var wrapperOutlinedTrailing = document.getElementById('demo-tf-outlined-trailing-wrapper');

        var tfIcons = document.querySelectorAll('.mdc-text-field__icon');
        var tfInputs = tfIconContainer.querySelectorAll('.mdc-text-field__input');

        document.getElementById('disable-leading-trailing').addEventListener('change', function(evt) {
          tfLeading.disabled = evt.target.checked;
          tfTrailing.disabled = evt.target.checked;
          tfOutlinedLeading.disabled = evt.target.checked;
          tfOutlinedTrailing.disabled = evt.target.checked;
        });

        document.getElementById('rtl-leading-trailing').addEventListener('change', function(evt) {
          if (evt.target.checked) {
            wrapperLeading.setAttribute('dir', 'rtl');
            wrapperTrailing.setAttribute('dir', 'rtl');
            wrapperOutlinedLeading.setAttribute('dir', 'rtl');
            wrapperOutlinedTrailing.setAttribute('dir', 'rtl');
          } else {
            wrapperLeading.removeAttribute('dir');
            wrapperTrailing.removeAttribute('dir');
            wrapperOutlinedLeading.removeAttribute('dir');
            wrapperOutlinedTrailing.removeAttribute('dir');
          }
          tfLeading.layout();
          tfTrailing.layout();
          tfOutlinedLeading.layout();
          tfOutlinedTrailing.layout();
        });

        document.getElementById('dense-leading-trailing').addEventListener('change', function(evt) {
          tfLeadingEl.classList[evt.target.checked ? 'add' : 'remove']('mdc-text-field--dense');
          tfLeading.layout();
          tfTrailingEl.classList[evt.target.checked ? 'add' : 'remove']('mdc-text-field--dense');
          tfTrailing.layout();
          tfOutlinedLeadingEl.classList[evt.target.checked ? 'add' : 'remove']('mdc-text-field--dense');
          tfOutlinedLeading.layout();
          tfOutlinedTrailingEl.classList[evt.target.checked ? 'add' : 'remove']('mdc-text-field--dense');
          tfOutlinedTrailing.layout();
        });

        document.getElementById('unclickable-leading-trailing').addEventListener('change', function(evt) {
          [].forEach.call(tfIcons, function (icon) {
            icon.setAttribute('tabindex', evt.target.checked ? '-1' : '0');
          });
        });

        document.getElementById('required-leading-trailing').addEventListener('change', function(evt) {
          var checked = evt.target.checked;
          toggleRequired(tfLeading, checked);
          toggleRequired(tfTrailing, checked);
          toggleRequired(tfOutlinedLeading, checked);
          toggleRequired(tfOutlinedTrailing, checked);
        });

        document.getElementById('pattern-leading-trailing').addEventListener('change', function(evt) {
          var checked = evt.target.checked;
          togglePattern(tfLeading, checked);
          togglePattern(tfTrailing, checked);
          togglePattern(tfOutlinedLeading, checked);
          togglePattern(tfOutlinedTrailing, checked);
        });

        document.getElementById('leading-trailing-alternate-colors').addEventListener('change', function(evt) {
          tfLeadingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-colors');
          tfLeadingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-error-colors');
          tfLeading.layout();
          tfTrailingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-colors');
          tfTrailingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-error-colors');
          tfTrailing.layout();
          tfOutlinedLeadingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-colors');
          tfOutlinedLeadingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-error-colors');
          tfOutlinedLeading.layout();
          tfOutlinedTrailingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-colors');
          tfOutlinedTrailingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-error-colors');
          tfOutlinedTrailing.layout();
        });
      });

      demoReady(function() {
        var section = document.getElementById('demo-text-field-wrapper');
        var tfRoot = section.querySelector('.mdc-text-field');
        var helperText = section.querySelector('.mdc-text-field-helper-text');
        var tf = new mdc.textField.MDCTextField(tfRoot);

        document.getElementById('disable').addEventListener('change', function(evt) {
          var target = evt.target;
          tf.disabled = target.checked;
        });
        document.getElementById('rtl').addEventListener('change', function(evt) {
          var target = evt.target;
          if (target.checked) {
            section.setAttribute('dir', 'rtl');
          } else {
            section.removeAttribute('dir');
          }
        });
        document.getElementById('dense').addEventListener('change', function(evt) {
          var target = evt.target;
          tfRoot.classList[target.checked ? 'add' : 'remove']('mdc-text-field--dense');
        });
        document.getElementById('required').addEventListener('change', function(evt) {
          toggleRequired(tf, evt.target.checked);
        });
        document.getElementById('alternate-colors').addEventListener('change', function (evt) {
          var target = evt.target;
          tfRoot.classList[target.checked ? 'add' : 'remove']('demo-text-field-custom-colors');
          tfRoot.classList[target.checked ? 'add' : 'remove']('demo-text-field-custom-error-colors');
        });
        document.getElementById('use-helper-text').addEventListener('change', function(evt) {
          var target = evt.target;
          helperText.style.visibility = target.checked ? 'visible' : 'hidden';
          document.getElementById('persistent-helper-text').disabled = !target.checked;
          document.getElementById('helper-text-as-validation').disabled = !target.checked;
        });
        document.getElementById('persistent-helper-text').addEventListener('change', function(evt) {
          var target = evt.target;
          helperText.classList[target.checked ? 'add' : 'remove'](
            'mdc-text-field-helper-text--persistent'
          );
        });
        document.getElementById('helper-text-as-validation').addEventListener('change', function(evt) {
          var target = evt.target;
          helperText.classList[target.checked ? 'add' : 'remove'](
            'mdc-text-field-helper-text--validation-msg'
          );
        });
      });

      demoReady(function() {
        var section = document.getElementById('demo-text-field-textarea-wrapper');
        var tfRoot = section.querySelector('.mdc-text-field');
        var tf = new mdc.textField.MDCTextField(tfRoot);
        document.getElementById('textarea-disable').addEventListener('change', function(evt) {
          var target = evt.target;
          tf.disabled = target.checked;
        });
        document.getElementById('textarea-rtl').addEventListener('change', function(evt) {
          var target = evt.target;
          if (target.checked) {
            section.setAttribute('dir', 'rtl');
          } else {
            section.removeAttribute('dir');
          }
        });

        document.getElementById('textarea-alternate-colors').addEventListener('change', function (evt) {
          var target = evt.target;
          tfRoot.classList[target.checked ? 'add' : 'remove']('demo-textarea');
        });
        document.getElementById('textarea-required').addEventListener('change', function(evt) {
          toggleRequired(tf, evt.target.checked);
        });
      });

      demoReady(function() {
        var section = document.getElementById('demo-fullwidth-wrapper');
        var tfRoot = section.querySelector('.mdc-text-field');
        var tfMultiRoot = section.querySelector('.mdc-text-field--textarea');
        var tf = new mdc.textField.MDCTextField(tfRoot);
        var tfMulti = new mdc.textField.MDCTextField(tfMultiRoot);

        document.getElementById('fullwidth-disable').addEventListener('change', function(evt) {
          var target = evt.target;
          [tf, tfMulti].forEach(function(component) {
            component.disabled = target.checked;
          });
        });

        document.getElementById('fullwidth-dense').addEventListener('change', function(evt) {
          var target = evt.target;
          [tfRoot, tfMultiRoot].forEach(function(el) {
            el.classList[target.checked ? 'add' : 'remove']('mdc-text-field--dense');
          });
        });

        document.getElementById('fullwidth-required').addEventListener('change', function(evt) {
          var checked = evt.target.checked;
          toggleRequired(tf, checked);
          toggleRequired(tfMulti, checked);
        });

        document.getElementById('fullwidth-alternate-colors').addEventListener('change', function (evt) {
          var target = evt.target;
          tfRoot.classList[target.checked ? 'add' : 'remove']('demo-fullwidth-input');
          tfMultiRoot.classList[target.checked ? 'add' : 'remove']('demo-textarea');
        });
      });

      demoReady(function() {
        var textFieldEl = document.querySelector('#demo-textfield-error-state');
        var textField = new mdc.textField.MDCTextField(textFieldEl);

        textFieldEl.addEventListener('input', function(event) {
          if (textField.valid) {
            textField.valid = true;
          }
        });
      });
    </script>
  </body>
</html>
